import 'package:json_annotation/json_annotation.dart';

part 'yearly_stats_model.g.dart';

/// 年度统计数据模型
@JsonSerializable()
class YearlyStatsModel {
  /// 天月
  @JsonKey(name: 'dayMonth')
  final String? dayMonth;

  /// 年月
  @JsonKey(name: 'yearMonth')
  final String yearMonth;

  /// 总支出金额
  @JsonKey(name: 'totalExpenseMoney')
  final int totalExpenseMoney;

  /// 总收入金额
  @JsonKey(name: 'totalIncomeMoney')
  final int totalIncomeMoney;

  /// 构造函数
  YearlyStatsModel({
    this.dayMonth,
    required this.yearMonth,
    required this.totalExpenseMoney,
    required this.totalIncomeMoney,
  });

  /// 从JSON创建对象
  factory YearlyStatsModel.fromJson(Map<String, dynamic> json) =>
      _$YearlyStatsModelFromJson(json);

  /// 转换为JSON
  Map<String, dynamic> toJson() => _$YearlyStatsModelToJson(this);

  /// 获取格式化后的总支出
  String get formattedExpense => '¥${totalExpenseMoney.toStringAsFixed(2)}';

  /// 获取格式化后的总收入
  String get formattedIncome => '¥${totalIncomeMoney.toStringAsFixed(2)}';

  /// 获取结余
  int get balance => totalIncomeMoney - totalExpenseMoney;

  /// 获取格式化后的结余
  String get formattedBalance => '¥${balance.toStringAsFixed(2)}';
}

/// 年度统计响应模型
@JsonSerializable()
class YearlyStatsResponse {
  /// 状态码
  final int code;

  /// 消息
  final String message;

  /// 年度统计数据
  final YearlyStatsModel data;

  /// 构造函数
  YearlyStatsResponse({
    required this.code,
    required this.message,
    required this.data,
  });

  /// 从JSON创建对象
  factory YearlyStatsResponse.fromJson(Map<String, dynamic> json) =>
      _$YearlyStatsResponseFromJson(json);

  /// 转换为JSON
  Map<String, dynamic> toJson() => _$YearlyStatsResponseToJson(this);
}